<?php
class AderezosController extends AppController
{
    public $uses = array('Aderezo','Insumo');
    public $layout = 'pizza';

    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
    
    public function index()
    {
        $aderezos = $this->Aderezo->find('all');
        $this->set(compact('aderezos'));
    }
    
    public function insertar()
    {
        if(!empty ($this->data))
        {
            $this->Aderezo->create();
                if($this->Aderezo->save($this->data))
                {
                    $this->Session->setFlash('Aderezo Registrado con Exito...!!!');
                    $this->redirect(array('action'=>'index'));
                }
                else {
                    $this->Session->setFlash('No se puedo registrar el Aderezo');
                }
        }
        $dinsumo = $this->Insumo->find('list',array('fields'=>'Insumo.nombre'));
        $this->set(compact('dinsumo'));
        //debug($dinsumo);exit;
    }
    function editar($id = null)
    {
        $this->Aderezo->id = $id;
        if (!$id) {
            $this->Session->setFlash('No Existe el tipo de Aderezo');
            $this->redirect(array('action' => 'index'));
        }
        if (empty($this->data)) {
            $this->data = $this->Aderezo->read();
            }
        else{
            if ($this->Aderezo->save($this->data)) {
                $this->Session->setFlash('Se Guardo Correctamente el Aderezo');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Error al Guardar el Aderezo');
            }
        }
        
        $dinsumo = $this->Insumo->find('list',array('fields'=>'Insumo.nombre'));
        $this->set(compact('dinsumo'));
    }
    function eliminar($id=null){
        $this->Aderezo->id=$id;
        $this->data=$this->Aderezo->read();
        if(!$id){
            $this->Session->setFlash('No existe el Aderezo a eliminar');
            $this->redirect(array('action' =>'index'));
        }
        else
        {
            if($this->Aderezo->delete($id)){
                $this->Session->setFlash('Se elimino el Aderezo '.$this->data['Aderezo']['nombre']);
                $this->redirect(array('action' =>'index'));
            }
            else{
                $this->Session->setFlash('Error al eliminar');
            }
        }
    }
}

?>
